package com.robot.auth.service;

import com.robot.auth.entity.JwtUser;
import com.robot.system.domain.entity.SysUser;
import com.robot.system.mapper.SysUserMapper;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {

    private SysUserMapper sysUserMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser sysUser = sysUserMapper.selectByName(s);
        if(sysUser == null) {
            throw new RuntimeException("账号不存在！");
        }
        return new JwtUser(sysUser);
    }
}
